package com.k2data.k2app.controller;

import com.k2data.k2app.response.CommonResultResponse;
import com.k2data.k2app.response.ResponseHelper;
import com.k2data.k2app.service.SmsService;
import com.k2data.k2app.validate.SmsMessage;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 阿里的短信接口
 */
@RestController
@Log4j2
@RequestMapping(path = "/sms")
public class SmsController {

    @Autowired
    private SmsService smsService;

//    @RequiresAuthentication
    @ApiOperation(value = "发送短信验证码")
    @RequestMapping(path = "/send", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<CommonResultResponse> sendSingleSms(@RequestBody SmsMessage smsMessage) throws Exception {
       String messageId =  smsService.sendSms(smsMessage);
        return ResponseHelper.success(messageId);
    }
    

}
